//
//  TenView.swift
//  swiftTS
//
//  Created by 航电 on 2020/3/31.
//  Copyright © 2020 航电. All rights reserved.
//

import UIKit

class TenView: UIView {

    private var fillColor = UIColor.lightGray;
    private var strokeColor = UIColor.green;
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    public func onChangeUIForTap(fill:UIColor,strock:UIColor) {
        self.fillColor = fill;
        self.strokeColor = strock;
        self.setNeedsDisplay();
    }
    
    override func draw(_ rect: CGRect) {
        super.draw(rect);
        
        guard let currentCT = UIGraphicsGetCurrentContext() else {
            return;
        }
        
        let path = CGMutablePath();
        path.move(to: CGPoint(x: self.frame.width/2, y: 20));
        path.addQuadCurve(to: CGPoint(x: self.frame.width, y: 20), control: CGPoint(x: self.frame.width/2+(self.frame.width/2-10)/2, y: 0));
        path.addQuadCurve(to: CGPoint(x: self.frame.width/2, y: self.frame.height), control: CGPoint(x: self.frame.width*7/8, y: self.frame.height*7/8));
        path.addQuadCurve(to: CGPoint(x: 0, y: 20), control: CGPoint(x: self.frame.width*1/8, y: self.frame.height*7/8));
        path.addQuadCurve(to: CGPoint(x: self.frame.width/2, y: 20), control: CGPoint(x: self.frame.width/2-(self.frame.width/2-10)/2, y: 0));
        
        currentCT.addPath(path);
        
        currentCT.setStrokeColor(self.strokeColor.cgColor);
        currentCT.setLineWidth(2);
        currentCT.setFillColor(self.fillColor.cgColor);
        
        currentCT.drawPath(using: .fillStroke);

    }
}
